/*
 * Created on 22.2.2007 by Mathew Stafurik
 */
package sk.sigp.eParser;

import java.util.HashMap;
import java.util.Map;

/**
 * class responsible for handling and holding with variables 
 *   @author Mathew Stafurik
 *   @version 1.0
 */
@SuppressWarnings("unchecked")
class VariableHolder {

    private Map varData=null;
    
    protected Map getVarData() {
        if (varData==null) {
            varData=new HashMap();
            varData.put("true",new Double(1));
            varData.put("false",new Double(0));
        }
        return varData;
    }

    public void insertVariable(String name,Object variable) {
        getVarData().put(name,variable);
    }
    
    public Object fetchVariable(String name) {        
        return varData.get(name);
    }
    
    public Double fetchVariableAsDouble(String name) {        
        Object o= varData.get(name);
        if (o instanceof String) {
            return new Double(name);
        } else if (o instanceof Number) {
            return new Double(((Number)o).doubleValue());
        } else return null;
    }
    
}
